package spells;
import main.Creature;
import main.Grid;

/*
 * A class that provides the basics that any spell in the game would need.
 */

public abstract class Spell {
	
	//asd
	
	double castTime;//how long it takes to cast a spell
	double cooldown; //the time the caster must wait before casting the spell again upon casting the spell
	double globalCooldown; //the time the caster must wait before doing any action again
	double curCooldown; //the time left on the cooldown that the caster must wait before casting the spell again
	int range;//the range of the spell in squares
	int radius;//how many squares are affected by a spell
	int maxHealthChange;//target max health change
	public int healthChange;//target health change
	int strChange;//target strength change
	int stamChange;//target stamina change
	int intChange;//target intelligence change
	int spChange;//target spirit change
	int manaChange;//target mana change
	int cMaxHealthChange;//caster max health change
	int cHealthChange;//caster health change
	int cStrChange;//caster strength change
	int cStamChange;//caster stamina change
	int cIntChange;//caster intelligence change
	int cSpChange;//caster spirit change
	public int cManaChange;//caster mana change
	String targetType;//what the spell targets (not used)
	String description;//a brief description of the spell
	String name;//the name of the spell
	boolean hasTarget;//whether the spell targets something
	Creature caster;//the creature casting the spell
	Creature target;//the target of the spell
	String element;//en element describing what the spell targets
	
	
	public Spell() {
		castTime=0;
		range=0;
		targetType="";
		hasTarget=false;
		
		//determine stat changes for target
		maxHealthChange=0;
		healthChange=0;
		strChange=0;
		stamChange=0;
		intChange=0;
		spChange=0;
		manaChange=0;
		
		//determine stat changes for caster
		cMaxHealthChange=0;
		cHealthChange=0;
		cStrChange=0;
		cStamChange=0;
		cIntChange=0;
		cSpChange=0;
		cManaChange=0;
		
		caster=null;
		target=null;
		name="";
	}//end constructor
	
	// a more detailed constructor that isn't being used at the moment
	public Spell (int cT, int ran, int rad, int hC, String tT,String desc, boolean hT, int st, int sta, int in, int sp, Creature c, Creature t, String n) {
		castTime=cT;
		range=ran;
		radius=rad;
		healthChange=hC;
		targetType=tT;
		description=desc;
		hasTarget=hT;
		strChange=st;
		stamChange=sta;
		intChange=in;
		spChange=sp;
		caster=c;
		target=t;
		name=n;
	}//end constructor
	
	//applies the spells effects
	public String applySpell(Grid g){
		if(target!=null || !hasTarget){
			double distance;
			if(hasTarget)
				distance=g.getDToEnemy(target);
			else
				distance=0;
			if(caster.curMana+cManaChange>=0 && distance<=range){
				//do effect to target if there is a target
				if(hasTarget){
					target.maxHealth+=maxHealthChange;
					target.curHealth+=healthChange;
					target.strength+=strChange;
					target.stamina+=stamChange;
					target.intelligence+=intChange;
					target.spirit+=spChange;
					target.curMana+=manaChange;
					if(target.curHealth<0)
						target.curHealth=0;
					if(target.curHealth>target.maxHealth)
						target.curHealth=target.maxHealth;
					if(target.curMana<0)
						target.curMana=0;
					if(target.curMana>target.maxMana)
						target.curMana=target.maxMana;
				}//end if
				
				//do effect to caster
				caster.maxHealth+=cMaxHealthChange;
				caster.curHealth+=cHealthChange;
				caster.strength+=cStrChange;
				caster.stamina+=cStamChange;
				caster.intelligence+=cIntChange;
				caster.spirit+=cSpChange;
				caster.curMana+=cManaChange;
				if(caster.curHealth<0)
					caster.curHealth=0;
				if(caster.curHealth>caster.maxHealth)
					caster.curHealth=caster.maxHealth;
				if(caster.curMana<0)
					caster.curMana=0;
				if(caster.curMana>caster.maxMana)
					caster.curMana=caster.maxMana;
				
				//determines what spell message to say
				if(hasTarget){
					return caster.name+" has cast "+name+" at "+target.name+" dealing "+healthChange+" damage";
				}
				else{
					return caster.name+" restores "+cHealthChange+" health";
				}
			}//end if
			//if you are out of range
			else if(distance>range){
				return "Out of range";
			}
			//if you are out of mana
			else{
				return "Not enough mana";
			}//end else
		}//end if
		return "";
	}//end method
	
	//set the target of a creature
	public void setTarget(Creature t){
		target=t;
	}//end method
	
	//get the creature name
	public String getName(){
		return name;
	}
	
	public double getCastTime()
	{
		return castTime;
	}
	
	
}//end class